<?php
/**
 * Created by IntelliJ IDEA.
 * User: ilya
 * Date: 21.06.11
 * Time: 14:23
 * To change this template use File | Settings | File Templates.
 */
 
class ExpressOlympChecker extends ServerPlugin {

    public function checkSolution($submission, $submission_id)
    {
        $right_answer = $this->problem->getResource('right answer');
        $user_answer = $submission['useranswer'];

        $right_answer = str_split($right_answer);
        $user_answer = str_split($user_answer);

        $l = count($right_answer);
        $l_user = count($user_answer);

        if ($l != $l_user)
            return array("scores" => 0, "usercheck" => "answer format error");

        $user_check = '';
        $scores = 0;

        for ($i = 0; $i < $l; $i++) {
            $right_symbol = $right_answer[$i];
            $user_symbol = $user_answer[$i];

            if ($user_symbol === '0') {
                $scores += 1;
                $user_check .= '0';
            } else if ($user_symbol != $right_symbol) {
                $user_check .= '-';
            } else {
                $scores += 2;
                $user_check .= '+';
            }
        }

        return array('scores' => '' . $scores, 'usercheck' => $user_check);

    }
}
